package com.chen.demo.util;

import cn.hutool.core.util.StrUtil;
import cn.hutool.dfa.SensitiveUtil;

import java.util.List;

public class DictUtil {
    /**
     * Hutool:处理敏感词
     * @return
     */
    public static String dictFiltering(String text){
        List<String> matchAll = SensitiveUtil.getFindedAllSensitive(text, false, false);
        if (matchAll.size() > 0) {
            for (String match : matchAll) {
                StringBuilder replace = new StringBuilder();
                for (int i = 0; i < StrUtil.length(match); i++) {
                    replace.append("*");
                }
                text = StrUtil.replace(text, match, replace.toString());
            }
        }
        return text;
    }
}
